package com.rockwell.maze800;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		setupStartButton();
		setupMaintenanceButton();
		setupTeachButton();
		setupSettingsButton();
		setupModbusButton();
		setupPathButton();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	private void setupStartButton() {
		Button start = (Button)findViewById(R.id.button_start);
		
		start.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startMission();
			}
			
		});
	}
	
	private void setupMaintenanceButton() {
		Button maintenance = (Button)findViewById(R.id.button_maintenance);
		
		maintenance.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startMaintenance();
			}
			
		});
	}
	
	private void setupTeachButton() {
		Button teach = (Button)findViewById(R.id.button_teach);
		
		teach.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				startTeach();
			}
			
		});
	}

	private void startMission() {
		Intent intent = new Intent(this, RobotActivity.class);
		startActivity(intent);
	}
	
	private void startMaintenance() {
		Intent intent = new Intent(this, MaintenanceActivity.class);
		startActivity(intent);
	}
	
	private void startTeach() {
		Intent intent = new Intent(this, TeachActivity.class);
		startActivity(intent);
	}
	
	private void setupSettingsButton() {
		Button settings = (Button)findViewById(R.id.button_settings);
		
		settings.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				changeSettings();
			}
			
		});
	}
	
	private void changeSettings() {
		Intent intent = new Intent(this, SettingsActivity.class);
		startActivity(intent);
	}
	
	private void setupModbusButton() {
		Button settings = (Button)findViewById(R.id.button_modbus);
		
		settings.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				testModbus();
			}
			
		});
	}

	private void testModbus() {
		Intent intent = new Intent(this, ModbusActivity.class);
		startActivity(intent);
	}
	
	private void setupPathButton() {
		Button path = (Button)findViewById(R.id.button_path);
		
		path.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				definePath();
			}
			
		});
	}

	private void definePath() {
		Intent intent = new Intent(this, MazeActivity.class);
		startActivity(intent);
	}
	
}
